<?php
/**
 * 会员资料模型
 * @author tangbl
 *
 */
class CustomModel extends Model {
    
	/**
	 array(
 		0.字段名
		1.验证规则 [require 字段必须、email 邮箱、url URL地址、currency 货币、number 数字]
		2.提示信息  {%usr_form_validata_email_email}
		3.验证条件 [0.(默认)存在字段就验证;1.必须验证;2.值不为空的时候验证]
		4.附加规则 [regex、function、callback、confirm、equal、in、length、between、
		         expire、ip_allow、ip_deny、unique]
		5.验证时   [1.新增数据时候验证;2.编辑数据时候验证;3.(默认)全部情况下验证]
	  );
	 */
	protected $_validate = array(

	);
	
	/**
	 * 定义自动完成
	 */
	protected $_auto     = array(
		array('addtime','time',1,'function'),
	);
	
	
	public function getRoleMember($cat){
		
		$time = $cat['time_view'];
		
		if($time==1){
			$begin = strtotime(date("Y-m-d"));
			$end   = strtotime(date("Y-m-d")." 23:59:59");
			$map['addtime'] = array("egt",$begin);
			$map['addtime'] = array("elt",$end);
		}elseif($time==2){
			$arr = $this->getWeek();
			$map['addtime'] = array("egt",$arr['begin']);
			$map['addtime'] = array("elt",$arr['end']);
		}elseif($time==3){
			$arr = $this->getMouth();
			$map['addtime'] = array("egt",$arr['begin']);
			$map['addtime'] = array("elt",$arr['end']);
		}
		return $map;
	}
	
	/**
	 * 获取本月时间戳
	 */
	public function getMouth(){
	
		$begin = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
		$end   = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
	
		return array("begin"=>strtotime($begin),"end"=>strtotime($end));
	}
	
	/**
	 * 获取本周时间戳
	 */
	public function getWeek(){
		$year = date("Y");
		$month = date("m");
		$day = date('w');
		$nowMonthDay = date("t");
	
		$firstday = date('d') - $day;
		if(substr($firstday,0,1) == "-"){
			$firstMonth = $month - 1;
			$lastMonthDay = date("t",$firstMonth);
			$firstday = $lastMonthDay - substr($firstday,1);
			$time_1 = strtotime($year."-".$firstMonth."-".$firstday." 23:59:59");
		}else{
			$time_1 = strtotime($year."-".$month."-".$firstday." 23:59:59");
		}
			
		$lastday = date('d') + (7 - $day);
		if($lastday > $nowMonthDay){
			$lastday = $lastday - $nowMonthDay;
			$lastMonth = $month + 1;
			$time_2 = strtotime($year."-".$lastMonth."-".$lastday." 23:59:59");
		}else{
			$time_2 = strtotime($year."-".$month."-".$lastday." 23:59:59");
		}
	
		return array("begin"=>$time_1,"end"=>$time_2);
	}
	
}